package br.jcrsistemas.componentes;

import java.awt.Component;
import java.awt.Container;
import java.awt.Panel;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import br.jcrsistemas.util.Acao;
import br.jcrsistemas.util.Configuracoes;

public class SysFrame extends JFrame implements InternalFrame {

	/**
     * 
     */
	private static final long serialVersionUID = 1L;
	// Lista de componentes do Frame
	private ArrayList<Component> listaComponentes = new ArrayList<Component>();
	private boolean habilitaMaximizar = false;
	protected JFrame form;

	// protected SisComRootPane rootPane;

	// public SysFrame() {
	// /**/
	// // $hide>>$
	// // if (Configuracoes.isSubstanceTheme()) {
	// // UIManager.setLookAndFeel(new SubstanceBusinessLookAndFeel());
	// // SubstanceBusinessLookAndFeel.setSkin(new OfficeSilver2007Skin());
	// // } else {
	// try {
	// // UIManager
	// // .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
	// UIManager.setLookAndFeel(new SubstanceBusinessLookAndFeel());
	// SubstanceBusinessLookAndFeel.setSkin(new OfficeSilver2007Skin());
	// } catch (UnsupportedLookAndFeelException e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// // }
	// SwingUtilities.updateComponentTreeUI(this);
	// setLocationRelativeTo(null);
	// // setResizable(isHabilitaMaximizar());
	// /**/
	// form = this;
	// // // $hide<<$
	// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	// // setBounds(100, 100, 1010, 720);
	// // $hide>>$
	// // setBounds(100, 100, Configuracoes.getWidth(),
	// // Configuracoes.getHeight());
	// // $hide<<$
	// setLocationRelativeTo(null);
	//
	// }

	public SysFrame() {
		super();
//		inicia();
		setLAF();
	}

	private void setLAF() {
		try {
			UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
			SwingUtilities.updateComponentTreeUI(this);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		setResizable(habilitaMaximizar);
	}

	public void inicia() {
		// $hide>>$
		setBounds(100, 100, Configuracoes.getWidth(), Configuracoes.getHeight());
		setLocationRelativeTo(null);
		// $hide<<$
	}

	@Override
	public Component add(Component arg0) {
		listaComponentes.add(arg0);

		return getContentPane().add(arg0);
	}

	public Component add(Component arg0, Panel painel) {
		listaComponentes.add(arg0);

		return painel.add(arg0);
	}

	@Override
	public void setContentPane(Container contentPane) {
		super.setContentPane(contentPane);
		setLocationRelativeTo(null);
		getContentPane().setLayout(null);
	}

	;

	// public boolean valida() {
	// for(Component component: listaComponentes) {
	// if(component instanceof SisComTextField) {
	// if( ( ((SisComTextField)component).isObrigatorio()) &&
	// (((SisComTextField)component).getText().isEmpty()) ) {
	// ((SisComTextField)component).requestFocus();
	// return false;
	// }
	// }
	// }
	// return true;
	// }

	public void setHabilitaMaximizar(boolean habilitaMaximizar) {
		this.habilitaMaximizar = habilitaMaximizar;
		this.setResizable(isHabilitaMaximizar());
	}

	public boolean isHabilitaMaximizar() {
		return habilitaMaximizar;
	}

	protected JFrame getForm() {
		return this;
	}

	@Override
	public JInternalFrame getInternalFrame() {
		JInternalFrame ret = new JInternalFrame(getTitle(), habilitaMaximizar,
				true, habilitaMaximizar, true);
		ret.setSize(getSize());
		ret.add(getContentPane());
		ret.setVisible(true);
		return ret;
	}

	public ArrayList<Component> getListaComponentes() {
		return listaComponentes;
	}
	
	public void doAoFechar() {}
	
	@Override
	public void dispose() {
		doAoFechar();
		super.dispose();
	}
	
	public void setAcao(Acao acao) {
		
	}

}
